package ge.telasi.tasks.ui.search;

import ge.telasi.tasks.search.Condition;
import ge.telasi.tasks.ui.UIUtils;
import javax.swing.Icon;

/**
 * Boolean field.
 * 
 * @author dimitri
 */
public class BooleanField extends Field {
    private boolean flag;

    public BooleanField(String name, String humanName) {
        super(name, humanName);
    }

    public boolean getFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
    
    @Override
    public String getType() {
        return "boolean";
    }

    @Override
    public Icon getIcon() {
        return UIUtils.getIcon16x16("tick.png");
    }

    @Override
    public Condition getCondition() {
        // create where condition
        StringBuilder b = new StringBuilder();
        b.append(" ( ");
        b.append(getSysName());
            b.append(" = ");
        b.append(flag ? 1 : 0);
        b.append(" ) ");
        String where = b.toString();

        // build condition
        Condition condition = new Condition();
        condition.setCondition(where);
        return condition;
    }

}